﻿package com.plter.controls.asmax
{
	import com.plter.controls.plter.PSprite;
	
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	/**
	 * ...
	 * @author Jaja as-max.cn
	 */
	internal class ASprite extends PSprite
	{
		public var bgShape:Shape = new Shape;
		
		/**
		 * 记录背景宽度
		 */
		private var theBgWidth:Number = 320;
		/**
		 * 记录背景高度
		 */
		private var theBgHeight:Number = 240;
		/**
		 * 记录填充颜色
		 */
		private var theFillColor:uint = 0xEEEEEE;
		/**
		 * 记录线条颜色
		 */
		private var theLineColor:uint = 0xCCCCCC;
		private var theEllipseWidth:uint = 5;
		private var theEllipseHeight:uint = 5;
		
		private var mat:Matrix = new Matrix;
		
		public function ASprite():void 
		{
			//建立矩阵
			mat.createGradientBox(10, 10, Math.PI / 2);
			
			addChild(bgShape);
		}
		
		/**
		 * 设置背景透明度
		 */
		public function set bgAlpha(value:Number):void {
			bgShape.alpha = value;
		}
		/**
		 * 获得背景透明度
		 */
		public function get bgAlpha():Number {
			return bgShape.alpha;
		}
		
		/**
		 * 指示背景宽度
		 */
		public function get bgWidth():Number {
			return theBgWidth;
		}
		/**
		 * 指示背景宽度
		 */
		public function set bgWidth(value:Number):void {
			theBgWidth = value;
		}
		
		/**
		 * 指示背景高度
		 */
		public function get bgHeight():Number {
			return theBgHeight;
		}
		/**
		 * 指示背景高度
		 */
		public function set bgHeight(value:Number):void {
			theBgHeight = value;
		}
		
		/**
		 * 指示背景填充色
		 */
		public function get bgFillColor():uint {
			return theFillColor;
		}
		/**
		 * 指示背景填充色
		 */
		public function set bgFillColor(value:uint):void {
			theFillColor = value;
			
			
		}
		
		
		/**
		 * 指示背景线条颜色
		 */
		public function get bgLineColor():uint {
			return theLineColor;
		}
		/**
		 * 指示背景线条颜色
		 */
		public function set bgLineColor(value:uint):void {
			theLineColor = value;
		}
		
		/**
		 * 指示背景圆角宽度
		 */
		public function get bgEllipseWidth():uint {
			return theEllipseWidth;
		}
		/**
		 * 指示背景圆角宽度
		 */
		public function set bgEllipseWidth(value:uint):void {
			theEllipseWidth = value;
		}
		
		/**
		 * 指示背景圆角高度
		 */
		public function get bgEllipseHeight():uint {
			return theEllipseHeight;
		}
		/**
		 * 指示背景圆角高度
		 */
		public function set bgEllipseHeight(value:uint):void {
			theEllipseHeight = value;
		}
		
		/**
		 * 绘制背景
		 * @param	wid				背景宽度
		 * @param	hei				背景高度
		 * @param	fillColor		填充颜色
		 * @param	lineColor		边框颜色
		 * @param	ellipseWidth	圆角宽度
		 * @param	ellipseHeight	圆角高度
		 */
		public function drawBG(wid:Number = 320, hei:Number = 240, fillColor:uint = 0xEEEEEE, lineColor:uint = 0xCCCCCC, ellipseWidth:int = 15, ellipseHeight:int = 15):void {
			//记录背景宽高
			theBgWidth = wid;
			theBgHeight = hei;
			theFillColor = fillColor;
			theLineColor = lineColor;
			theEllipseWidth = ellipseWidth;
			theEllipseHeight = ellipseHeight;
			
			bgShape.graphics.clear();
			bgShape.graphics.beginFill(fillColor);
			bgShape.graphics.lineStyle(1.5, lineColor);
			bgShape.graphics.drawRoundRect(0, 0, wid, hei, ellipseWidth, ellipseHeight);
			bgShape.graphics.endFill();
		}
		
		/**
		 * 绘制线型上下渐变背景
		 * @param	wid				背景宽度
		 * @param	hei				背景高度
		 * @param	fillColor		填充颜色
		 * @param	lineColor		边框颜色
		 * @param	ellipseWidth	圆角宽度
		 * @param	ellipseHeight	圆角高度
		 */
		public function drawLinedBG(wid:Number = 320, hei:Number = 240, fillColor:uint = 0xEEEEEE, lineColor:uint = 0xCCCCCC, ellipseWidth:int = 15, ellipseHeight:int = 15):void {
			//记录背景宽高
			theBgWidth = wid;
			theBgHeight = hei;
			theFillColor = fillColor;
			theLineColor = lineColor;
			theEllipseWidth = ellipseWidth;
			theEllipseHeight = ellipseHeight;
			
			bgShape.graphics.clear();
			bgShape.graphics.beginGradientFill(GradientType.LINEAR, [0xFFFFFF, fillColor], [1, 1], [0x00, 0xFF], mat);
			bgShape.graphics.lineStyle(1, lineColor);
			bgShape.graphics.drawRoundRect(0, 0, wid, hei, ellipseWidth, ellipseHeight);
			bgShape.graphics.endFill();
		}
		
		/**
		 * 绘制路径
		 * @param	pointArr	点阵
		 * @param	displayArea	绘制图形的显示区域
		 */
		public function drawPathOnSprite(pointArr:Array, displayArea:Sprite):void {
			displayArea.graphics.moveTo(pointArr[0].x, pointArr[0].y);
			
			for (var i:int = 1; i < pointArr.length; i++) {
				displayArea.graphics.lineTo(pointArr[i].x, pointArr[i].y);
			}
		}
		
		/**
		 * 绘制路径
		 * @param	pointArr	点阵
		 * @param	displayArea	绘制图形的显示区域
		 */
		public function drawPathOnShape(pointArr:Array, displayArea:Shape):void {
			displayArea.graphics.moveTo(pointArr[0].x, pointArr[0].y);
			
			for (var i:int = 1; i < pointArr.length; i++) {
				displayArea.graphics.lineTo(pointArr[i].x, pointArr[i].y);
			}
			
		}
		
		/**
		 * 刷新背景
		 */
		public function refreshBG():void {
			drawBG(bgWidth, bgHeight, bgFillColor, bgLineColor, bgEllipseWidth, bgEllipseHeight);
		}
		
	}
	
}